package com.whisperarts.financer.app;

import org.eclipse.jface.action.*;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import com.whisperarts.financer.app.actions.*;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

	private IWorkbenchAction exitAction;
	private IWorkbenchAction aboutAction;
	private IWorkbenchAction addAccountAction;
	private IWorkbenchAction editAccountAction;
	private IWorkbenchAction deleteAccountAction;
	private IWorkbenchAction preferenceAction;
	private IWorkbenchAction showCategoryViewAction;
	private IWorkbenchAction addCategoryAction;
	private IWorkbenchAction addTransactionAction;
	private IWorkbenchAction editTransactionAction;
	private IWorkbenchAction deleteTransactionAction;
	
    public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
        super(configurer);
    }

    @Override
	protected void makeActions(IWorkbenchWindow window) {
    	exitAction = ActionFactory.QUIT.create(window);
		register(exitAction);
		aboutAction = ActionFactory.ABOUT.create(window);
		register(aboutAction);
		addAccountAction = new AddAccountAction(window);
		register(addAccountAction);
		editAccountAction = new EditAccountAction(window);
		register(editAccountAction);
		deleteAccountAction = new DeleteAccountAction(window);
		register(deleteAccountAction);
		preferenceAction = ActionFactory.PREFERENCES.create(window);
		register(preferenceAction);
		showCategoryViewAction = new ShowCategoryViewAction(window);
		register(showCategoryViewAction);
		addCategoryAction = new AddCategoryAction(window);
		register(addCategoryAction);
		addTransactionAction = new AddTransactionAction(window);
		register(addTransactionAction);
		editTransactionAction = new EditTransactionAction(window);
		register(editTransactionAction);
		deleteTransactionAction = new DeleteTransactionAction(window);
		register(deleteTransactionAction);
    }


	@Override
	protected void fillMenuBar(IMenuManager menuBar) {
		MenuManager hyperbolaMenu = new MenuManager(
				"&Financer", "financer");
		MenuManager helpMenu = new MenuManager("&Help", "help");
		hyperbolaMenu.add(helpMenu);
		helpMenu.add(aboutAction);
		hyperbolaMenu.add(exitAction);
		
		MenuManager accountsMenu = new MenuManager(
				"&Accounts", "accounts");
		accountsMenu.add(addAccountAction);
		
		MenuManager optionsMenu = new MenuManager(
				"&Options", "options");
		optionsMenu.add(preferenceAction);	
		
		menuBar.add(hyperbolaMenu);
		menuBar.add(accountsMenu);		
		menuBar.add(optionsMenu);		
	}
	
	@Override
	protected void fillCoolBar(ICoolBarManager coolBar) {
		IToolBarManager toolbar = new ToolBarManager(coolBar.getStyle());
		toolbar.add(addAccountAction);
		toolbar.add(editAccountAction);
		toolbar.add(new Separator());		
		toolbar.add(deleteAccountAction);
		IToolBarManager toolbar2 = new ToolBarManager(coolBar.getStyle());
		toolbar2.add(showCategoryViewAction);
		toolbar2.add(addCategoryAction);
		IToolBarManager toolbarTransactions = new ToolBarManager(coolBar.getStyle());
		toolbarTransactions.add(addTransactionAction);
		toolbarTransactions.add(editTransactionAction);
		toolbarTransactions.add(deleteTransactionAction);
		coolBar.add(toolbar);
		coolBar.add(toolbar2);
		coolBar.add(toolbarTransactions);
		
	}
	
	protected void fillTrayItem(IMenuManager trayItem) {
		trayItem.add(addTransactionAction);
		trayItem.add(exitAction);
	}
}
